package org.fuyd.dao;

import java.util.List;

import org.fuyd.model.CusQRCode;
import org.springframework.orm.hibernate3.HibernateTemplate;

public class CusQRCodeDaoImpl implements CusQRCodeDao {

  private HibernateTemplate hibernateTemplate;

  public void add(CusQRCode cusQRCode) {
    this.hibernateTemplate.save(cusQRCode);
  }

  public CusQRCode findByUuid(String qrCodeUuid) {
    List<?> cusQRCodes =
        this.hibernateTemplate.find("from CusQRCode c where c.qrCodeUuid = ?", qrCodeUuid);
    return (CusQRCode) cusQRCodes.get(0);
  }

  public HibernateTemplate getHibernateTemplate() {
    return hibernateTemplate;
  }

  public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
    this.hibernateTemplate = hibernateTemplate;
  }

  public void update(String qrCodeUuid, int customerId) {
    // 先根据uuid查找出CusQRCode
    CusQRCode cusQRCode = this.findByUuid(qrCodeUuid);
    cusQRCode.setCustomerId(customerId);
    this.hibernateTemplate.update(cusQRCode);
  }

}
